package cn.xdd._10PriorityQueue;

import cn.xdd.utils.RabbitMqUtils;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;

import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * @author user_xdd
 * @Date 2022-05-10 13:46
 * @description
 *  1.队列添加优先级，定义有多少个优先级
 *    arguments.put("x-max-priority", 10);
 *  2.给消息定义优先级
 *      AMQP.BasicProperties basicProperties=new AMQP.BasicProperties().builder().priority(5).build();
 *
 * @return
 */
public class Producter {
    private final static String QUEUE_NAME = "hello";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();
        //-------------------------------队列添加优先级，定义有多少个优先级 -------------------------------
        Map<String, Object> arguments=new HashMap<>();
        arguments.put("x-max-priority", 10);
        channel.queueDeclare(QUEUE_NAME,true,false,false,arguments);
        //-------------------------------给消息定义优先级 -------------------------------
        AMQP.BasicProperties basicProperties=new AMQP.BasicProperties().builder().priority(5).build();

       for(int i=0;i<10;i++){
            String  message="info"+i;

           if(i==5){
                channel.basicPublish("",QUEUE_NAME,basicProperties,message.getBytes());
           }else {
               channel.basicPublish("",QUEUE_NAME,null,message.getBytes());
           }
       }
        System.out.println("发送成功");

    }
}
